/*
题目链接：https://leetcode.cn/problems/rotated-digits/description/
	刘沛民	2024-12-3
*/

class Solution {
private:
    inline bool goodDigit(const int i){
        return i == 2 || i == 5 || i == 6 || i == 9;
    }
    inline bool badDigit(const int i){
        return i == 4 || i == 7 || i == 3;
    }
    bool goodNum(int n){
        bool foundGood = false;
        while(n>0){
            if((!foundGood) && goodDigit(n % 10)){
                foundGood = true;
            }
            if(badDigit(n % 10)){
                return false;
            }
            n /= 10;
        }
        return foundGood;
    }
public:
    int rotatedDigits(int n) {
        int count= 0;
        for(int i=1;i<=n;++i){
            count += goodNum(i) ? 1:0;
        }
        return count;
    }
};